package com.htu.edu.controller;

import com.htu.edu.bean.Business;
import com.htu.edu.common.R;
import com.htu.edu.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
// 2. 设置该模块的请求路径，如/user
@RequestMapping("/Business")
// 3. 解决跨域
@CrossOrigin
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    @GetMapping("/listBusinessByOrderTypeId/{OrderTypeId}")
    public R listBusinessByOrderTypeId(@PathVariable("OrderTypeId") String OrderTypeId){
        try {
            List<Business> businesses = businessService.listBusinessByOrderTypeId(OrderTypeId);
            return R.ok().data(businesses);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @GetMapping("/getBusinessById/{businessId}")
    public R getBusinessById(@PathVariable("businessId") String businessId ){
        try {
            Business businessById = businessService.getBusinessById(businessId);
            return R.ok().data(businessById);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
